# Maintainer: Natanael Copa <ncopa@alpinelinux.org>

# this aport only includes glib/gtk support in order to break the
# circular make dependency: gtk <- cups <- poppler <- gtk

pkgname=poppler-qt5
_pkgname=poppler
pkgver=22.07.0
pkgrel=0
pkgdesc="PDF rendering library based on xpdf 3.0"
url="https://poppler.freedesktop.org/"
arch="all"
license="GPL-2.0-only"
replaces="poppler-glib"
provides="poppler-qt4=$pkgver-$pkgrel"
options="!check" # Requires dl of testfiles and only checks qt5 libs
makedepends="
	cairo-dev
	cmake
	fontconfig-dev
	jpeg-dev
	lcms2-dev
	libjpeg-turbo-dev
	libpng-dev
	libxml2-dev
	openjpeg-dev
	openjpeg-tools
	poppler-dev>=$pkgver
	qt5-qtbase-dev
	samurai
	tiff-dev
	zlib-dev
	"
depends_dev="$makedepends"
subpackages="$pkgname-dev"
source="https://poppler.freedesktop.org/poppler-$pkgver.tar.xz"
builddir="$srcdir/$_pkgname-$pkgver"

prepare() {
	default_prepare

	local _linked_pkg=poppler
	local _linked_apkbuild="$startdir"/../../main/$_linked_pkg/APKBUILD
	mkdir -p "$builddir"
	if  [ -f "$_linked_apkbuild" ]; then
		local _linked_ver=$( . "$_linked_apkbuild"; echo "$pkgver")
		if [ "$_linked_ver" != "$pkgver" ]; then
			error "pkgver needs to be identical with $_linked_pkg ($_linked_ver)"
			return 1
		fi
	fi
}

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DENABLE_UNSTABLE_API_ABI_HEADERS=ON \
		-DBUILD_GTK_TESTS=OFF \
		-DBUILD_QT5_TESTS=ON \
		-DBUILD_CPP_TESTS=OFF \
		-DENABLE_QT5=ON \
		-DENABLE_BOOST=OFF \
		$CMAKE_CROSSOPTS
	cmake --build build
}

package() {
	install -Dm644 build/poppler-qt5.pc "$pkgdir"/usr/lib/pkgconfig/poppler-qt5.pc
	DESTDIR="$pkgdir" cmake --install build/qt5
}

sha512sums="
d3d8a0f50ddcf2020bbbc3c21c6fcdd6f31b431d984622c2a4ae4986b82a14d79969d7113588ba5d9a672babe4dc01fe2f5e8d9ce73a9fbce14685220d914f02  poppler-22.07.0.tar.xz
"
